package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.SetmealDish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Api("套餐操作接口")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    /**
     * 套餐分页查询
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(SetmealPageQueryDTO pageQueryDTO){
        PageResult result = setmealService.page(pageQueryDTO);
        return Result.success(result);
    }
    /**
     * 套餐状态修改
     * @return
     */
    @PostMapping("/status/{status}")
    public Result status(@PathVariable Integer status, Integer id){
         setmealService.status(status,id);
        return Result.success();
    }

    /**
     * 新增套餐
     *
     */
    @PostMapping()
    public Result insert(@RequestBody SetmealDTO setmealDTO){
        setmealService.insert(setmealDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getByID(@PathVariable Long id){
        SetmealVO setmealVO = setmealService.getSetmealByID(id);
        return Result.success(setmealVO);
    }

    @PutMapping()
    @ApiOperation("修改套餐")
    public Result update(@RequestBody SetmealDTO setmealDTO){
        setmealService.update(setmealDTO);
        return Result.success();
    }
    @DeleteMapping
    @ApiOperation("删除套餐")
    public Result delete(String ids){
        String[] split = ids.split(",");
        setmealService.delete(split);
        return Result.success();
    }
}
